package com.benyq.networkprogramme

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v4.content.ContextCompat
import android.util.Log
import android.view.MenuItem
import com.benyq.networkprogramme.ftp.FtpHelper
import kotlinx.android.synthetic.main.activity_ftp.*
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors

class FtpActivity : AppCompatActivity() {

    private var executorService: ExecutorService = Executors.newSingleThreadExecutor()
    private val fragmentAdapter by lazy { FragmentAdapter(supportFragmentManager) }

    private val uploadFragment by lazy { FileFragment.getInstance(FileFragment.typeUpload) }
    private val downFragment by lazy { FileFragment.getInstance(FileFragment.typeDown) }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_ftp)

        initView()
    }

    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        if (item?.itemId == android.R.id.home) {
            finish()
            return true
        }
        return super.onOptionsItemSelected(item)
    }

    fun initView(){
        mainToolbar.title = "FTP"
        setSupportActionBar(mainToolbar)
        mainToolbar.navigationIcon = ContextCompat.getDrawable(this, R.drawable.ic_action_back)

        viewPager.currentItem = 0

        fragmentAdapter.addFragment("上传", uploadFragment)
        fragmentAdapter.addFragment("下载", downFragment)
        viewPager.adapter = fragmentAdapter
        tabLayout.setupWithViewPager(viewPager)
    }
}
